home *** CD-ROM | disk | FTP | other *** search
- /* Whetstone benchmark. Used for compile comparison. This program
- has a long history and is well described in "A Synthetic Benchmark"
- by H.J. Curnow and B.A. Wichman in Computer Journal, Vol 19 #1,
- Feburary 1976.
-
- Time the compiles with and without the optimizer as follows:
-
- time cc -o whet whet.c -lm
- time cc -O -o whet.opt whet.c -lm
-
- Then time the runs of both versions as follows:
-
- time whet
- time whet.opt
- */
-
- #define ITERATIONS 2
- #define PNT5MINUS 0.499975
- #define PNT5PLUS 0.50025
- #define TWO 2.0
-
- #include <math.h>
- #include "timer.h"
-
- main()
- {
- static int mod1freq, mod2freq, mod3freq, mod4freq, mod6freq;
- static int mod7freq, mod8freq, mod9freq, mod10freq, mod11freq;
- static double ary[4];
- static double real1, real2, real3, real4;
- register int cntr;
- register int int1, int2, int3;
-
- init_timer();
- start_timer();
- /* Establish execution frequencies */
-
- mod1freq = 0 * ITERATIONS;
- mod2freq = 12 * ITERATIONS;
- mod3freq = 14 * ITERATIONS;
- mod4freq = 345 * ITERATIONS;
- mod6freq = 210 * ITERATIONS;
- mod7freq = 32 * ITERATIONS;
- mod8freq = 899 * ITERATIONS;
- mod9freq = 616 * ITERATIONS;
- mod10freq = 0 * ITERATIONS;
- mod11freq = 93 * ITERATIONS;
-
- /* Module 1: simple identifiers */
-
- real1 = 1.0;
- real2 = -1.0;
- real3 = -1.0;
- real4 = -1.0;
- for(cntr = 1; cntr <= mod1freq; cntr += 1)
- {
- real1 = (real1 + real2 + real3 - real4) * PNT5MINUS;
- real2 = (real1 + real2 - real3 - real4) * PNT5MINUS;
- real3 = (real1 - real2 + real3 + real4) * PNT5MINUS;
- real4 = (real2 - real1 + real3 + real4) * PNT5MINUS;
- } /* for */
-
- /* Module 2: array elements */
-
- ary[1] = 1.0;
- ary[2] = -1.0;
- ary[3] = -1.0;
- ary[4] = -1.0;
- for(cntr = 1; cntr <= mod2freq; cntr += 1)
- {
- ary[1] = (ary[1] + ary[2] + ary[3] - ary[4]) * PNT5MINUS;
- ary[2] = (ary[1] + ary[2] - ary[3] + ary[4]) * PNT5MINUS;
- ary[3] = (ary[1] - ary[2] + ary[3] + ary[4]) * PNT5MINUS;
- ary[4] = (ary[2] - ary[1] + ary[3] + ary[4]) * PNT5MINUS;
- } /* for */
-
-
- /* Module 3: array as parameter ( see program at end ) */
-
- for(cntr = 1; cntr <= mod3freq; cntr += 1)
- mod3(ary);
-
- /* Module 4: conditional jumps */
-
- int1 = 1;
- for(cntr = 1; cntr <= mod4freq; cntr += 1)
- {
- if(int1 == 1)
- int1 = 2;
- else
- int1 = 3;
- if (int1 > 2)
- int1 = 0;
- else
- int1 = 1;
-
- if (int1 < 1)
- int1 = 1;
- else
- int1 = 0;
- } /* for */
-
- /* Module 6: integer arithmetic using arrays */
-
- int1 = 1;
- int2 = 2;
- int3 = 3;
- for(cntr = 1; cntr <= mod6freq; cntr += 1)
- {
- int1 = int1 * (int2 - int1) * (int3 - int2);
- int2 = int3 * int2 - (int3 - int1) * int2;
- int3 = (int3 - int2) * (int2 + int1);
-
- ary[int3 - 1] = int1 + int2 + int3;
- ary[int2 - 1] = int1 * int2 * int3;
- }
-
- /* Module 7: trigonometric functions */
-
- real1 = 0.5;
- real2 = 0.5;
- for(cntr = 1; cntr <= mod7freq; cntr += 1)
- {
- real1 = atan(TWO * sin(real1) * cos(real1) / (cos(real1 + real2) +
- cos(real1 - real2) - 1.0)) * PNT5MINUS;
- real2 = atan(TWO * sin(real2) * cos(real2) / (cos(real1 + real2) +
- cos(real1 - real2) - 1.0)) * PNT5MINUS;
- }
-
- /* Module 8: procedure calls */
-
- real1 = real2 = real3 = 1.0;
- for(cntr = 1; cntr <= mod8freq; cntr += 1)
- mod8(real1, real2, &real3);
-
- /* Module 9: array references */
- int1 = 1;
- int2 = 2;
- int3 = 3;
- ary[1] = 1.0;
- ary[2] = 2.0;
- ary[3] = 3.0;
- for(cntr = 1; cntr <= mod9freq; cntr += 1)
- {
- ary[int1] = ary[int2];
- ary[int2] = ary[int3];
- ary[int3] = ary[int1];
- }
-
- /* Module 10: integer arithmetic */
-
- int1 = 2;
- int2 = 3;
- for(cntr = 1; cntr <= mod10freq; cntr += 1)
- {
- int1 = int1 + int2;
- int2 = int1 + int2;
- int1 = int2 - int1;
- int2 = int2 - int1 - int1;
- }
-
- /* Module 11: standard functions */
-
- real1 = 0.75;
- for(cntr = 1; cntr <= mod11freq; cntr += 1)
- real1= sqrt( exp( log(real1) / PNT5PLUS));
-
- print_elapsed("Whetstone floating point benchmark",REALMIN,USERMIN, SYSTEMMIN);
- exit(0);
- /* end of main program */
- }
-
- /* Module 3 routine */
-
- mod3(a)
- double a[4];
-
- {
- int cntr;
- for(cntr = 0; cntr <= 6; cntr += 1)
- {
- a[1] = (a[1] + a[2] + a[3] - a[4]) * PNT5MINUS;
- a[2] = (a[1] + a[2] - a[3] + a[4]) * PNT5MINUS;
- a[3] = (a[1] - a[2] + a[3] + a[4]) * PNT5MINUS;
- a[4] = (-a[1] + a[2] + a[3] + a[4]) / TWO;
- } /* for */
- }
-
- /* Module 8 routine */
-
- mod8(r1, r2, r3)
- double r1, r2, *r3;
- {
- double tmp1, tmp2;
-
- tmp1 = r1;
- tmp2 = r2;
-
- tmp1 = PNT5MINUS * (tmp1 + tmp2);
- tmp2 = PNT5MINUS * (tmp1 + tmp2);
- *r3 = (tmp1 + tmp2) / TWO;
- }
-